package il.ac.braude.sona.gui.forms.myforms;

import il.ac.braude.sona.constants.ButtonPermission;
import il.ac.braude.sona.constants.Resources;
import il.ac.braude.sona.entities.ChangeRequest;
import il.ac.braude.sona.gui.forms.FormFrame;
import il.ac.braude.sona.gui.forms.FormPanel;
import il.ac.braude.sona.gui.forms.questions.QButton;
import il.ac.braude.sona.gui.forms.questions.QComboBox;
import il.ac.braude.sona.gui.forms.questions.QTextArea;

import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JLabel;
/**
 * The SurveyReportForm class contains methods that create the GUI for write, edit and view survey report
 * @author  Ofek Ron
 * @author Avihay Avitan
 * @author Nitzan Inbar
 * @author Sasha Rozenthal
 * Laboratory in Software Engineering,Ort Braude College.</p>
 *
 */
public class SurveyReportForm extends FormFrame {
	/**
	 *  the survey description
	 */
	private QTextArea SurveyReportDescription= new QTextArea(Resources.Strings.SurveyReportDescription);
	/**
	 *  the survey results
	 */
	private QTextArea SurveyReportResults= new QTextArea(Resources.Strings.SurveyReportResults);
	/**
	 *  the survey constraints
	 */
	private QTextArea SurveyReportConstraints= new QTextArea(Resources.Strings.SurveyReportConstraints);
	/**
	 *  the survey risks
	 */
	private QTextArea SurveyReportRisks= new QTextArea(Resources.Strings.SurveyReportRisks);
	/**
	 *  the survey evaluated days
	 */
	private QComboBox SurveyReportEvaluatedDays= new QComboBox(Resources.Strings.SurveyReportEvaluatedDays,1,99);
	/**
	 *  the board additional data
	 */
	public QTextArea SurveyReportAdditionalData= new QTextArea(Resources.Strings.SurveyReportAdditionalData);
	/**
	 *  the additional data button for board members only
	 */
	public QButton additionalDataButton;
	
	/**
	 * Creates the GUI for writing new survey report
	 * @param req  - the request that report is written for
	 */
	public SurveyReportForm(ChangeRequest req) {
		super(ButtonPermission.WriteSurveyReport, Resources.Strings.OK);
		FormPanel form = new FormPanel();
		form.addTitleWithUnderline(ButtonPermission.WriteSurveyReport+" for request: "+req.getID());
		form.addTitle("Information system: "+req.getValue("Information System"));
		form.addQuestion(SurveyReportDescription);
		form.addQuestion(SurveyReportResults);
		form.addQuestion(SurveyReportConstraints);
		form.addQuestion(SurveyReportRisks);
		form.addQuestion(SurveyReportEvaluatedDays);
		setFormPanel(form);
	}
	/**
	 * Creates the GUI for viewing the survey report 
	 * @param list - contains the data of the survey report
	 * @param actionListener - the listener for additional data button 
	 */
	public SurveyReportForm(ArrayList<String> list, ActionListener actionListener) {
		super(ButtonPermission.ViewSurveyReport, Resources.Strings.OK);
		FormPanel form = new FormPanel();
		form.addTitleWithUnderline(ButtonPermission.ViewSurveyReport+", request: "+list.get(0));
		form.addTitle("Written by: "+list.get(1));
		form.addTitle("Information system: "+list.get(2));
		SurveyReportDescription.setDefaultAnswer(list.get(3));
		SurveyReportDescription.setEditable(false);
		SurveyReportResults.setDefaultAnswer(list.get(4));
		SurveyReportResults.setEditable(false);
		SurveyReportConstraints.setDefaultAnswer(list.get(5));
		SurveyReportConstraints.setEditable(false);
		SurveyReportRisks.setDefaultAnswer(list.get(6));
		SurveyReportRisks.setEditable(false);
		SurveyReportAdditionalData.setVisible(false);
		form.addQuestion(SurveyReportDescription);
		form.addQuestion(SurveyReportResults);
		form.addQuestion(SurveyReportConstraints);
		form.addQuestion(SurveyReportRisks);
		form.addTitle(Resources.Strings.SurveyReportEvaluatedDays+" "+list.get(7));
		form.addQuestion(additionalDataButton=new QButton(Resources.Strings.SurveyRequestAdditionalData,actionListener));
		form.addQuestion(SurveyReportAdditionalData);
		setFormPanel(form);

	}
	/**
	 * Creates the GUI for editing the survey report (after requested additional data) 
	 * @param list - the old report that has been written and need additiona data
	 */
	public SurveyReportForm(ArrayList<String> list) {
		super(ButtonPermission.EditSurveryReport, Resources.Strings.OK);
		FormPanel form = new FormPanel();
		form.addTitleWithUnderline(ButtonPermission.EditSurveryReport+", request: "+list.get(0));
		form.addTitle("Information system: "+list.get(2));
		SurveyReportDescription.setDefaultAnswer(list.get(3));
		SurveyReportResults.setDefaultAnswer(list.get(4));
		SurveyReportConstraints.setDefaultAnswer(list.get(5));
		SurveyReportRisks.setDefaultAnswer(list.get(6));
		SurveyReportAdditionalData.setDefaultAnswer(list.get(8));
		SurveyReportAdditionalData.setEditable(false);
		SurveyReportEvaluatedDays.setDefaultAnswer(Integer.parseInt(list.get(7)));
		form.addQuestion(SurveyReportDescription);
		form.addQuestion(SurveyReportResults);
		form.addQuestion(SurveyReportConstraints);
		form.addQuestion(SurveyReportRisks);
		form.addQuestion(SurveyReportEvaluatedDays);
		form.addQuestion(SurveyReportAdditionalData);
		setFormPanel(form);
	}

}
